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;
42 static unsigned int tcp_child_ehash_entries_max = 16 * 1024 * 1024;
45 static int sysctl_tcp_low_latency __read_mostly;
47 /* Update system visible IP port range */
48 static void set_local_port_range(struct net *net, int range[2])
50 bool same_parity = !((range[0] ^ range[1]) & 1);
52 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
53 if (same_parity && !net->ipv4.ip_local_ports.warned) {
54 net->ipv4.ip_local_ports.warned = true;
55 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
57 net->ipv4.ip_local_ports.range[0] = range[0];
58 net->ipv4.ip_local_ports.range[1] = range[1];
59 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
62 /* Validate changes from /proc interface. */
63 static int ipv4_local_port_range(struct ctl_table *table, int write,
64 void *buffer, size_t *lenp, loff_t *ppos)
67 container_of(table->data, struct net, ipv4.ip_local_ports.range);
70 struct ctl_table tmp = {
72 .maxlen = sizeof(range),
74 .extra1 = &ip_local_port_range_min,
75 .extra2 = &ip_local_port_range_max,
78 inet_get_local_port_range(net, &range[0], &range[1]);
80 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
82 if (write && ret == 0) {
83 /* Ensure that the upper limit is not smaller than the lower,
84 * and that the lower does not encroach upon the privileged
87 if ((range[1] < range[0]) ||
88 (range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock)))
91 set_local_port_range(net, range);
97 /* Validate changes from /proc interface. */
98 static int ipv4_privileged_ports(struct ctl_table *table, int write,
99 void *buffer, size_t *lenp, loff_t *ppos)
101 struct net *net = container_of(table->data, struct net,
102 ipv4.sysctl_ip_prot_sock);
106 struct ctl_table tmp = {
108 .maxlen = sizeof(pports),
110 .extra1 = &ip_privileged_port_min,
111 .extra2 = &ip_privileged_port_max,
114 pports = READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
116 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
118 if (write && ret == 0) {
119 inet_get_local_port_range(net, &range[0], &range[1]);
120 /* Ensure that the local port range doesn't overlap with the
121 * privileged port range.
123 if (range[0] < pports)
126 WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports);
132 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
134 kgid_t *data = table->data;
136 container_of(table->data, struct net, ipv4.ping_group_range.range);
139 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
143 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
146 /* Update system visible IP port range */
147 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
149 kgid_t *data = table->data;
151 container_of(table->data, struct net, ipv4.ping_group_range.range);
152 write_seqlock(&net->ipv4.ping_group_range.lock);
155 write_sequnlock(&net->ipv4.ping_group_range.lock);
158 /* Validate changes from /proc interface. */
159 static int ipv4_ping_group_range(struct ctl_table *table, int write,
160 void *buffer, size_t *lenp, loff_t *ppos)
162 struct user_namespace *user_ns = current_user_ns();
166 struct ctl_table tmp = {
168 .maxlen = sizeof(urange),
170 .extra1 = &ip_ping_group_range_min,
171 .extra2 = &ip_ping_group_range_max,
174 inet_get_ping_group_range_table(table, &low, &high);
175 urange[0] = from_kgid_munged(user_ns, low);
176 urange[1] = from_kgid_munged(user_ns, high);
177 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
179 if (write && ret == 0) {
180 low = make_kgid(user_ns, urange[0]);
181 high = make_kgid(user_ns, urange[1]);
182 if (!gid_valid(low) || !gid_valid(high))
184 if (urange[1] < urange[0] || gid_lt(high, low)) {
185 low = make_kgid(&init_user_ns, 1);
186 high = make_kgid(&init_user_ns, 0);
188 set_ping_group_range(table, low, high);
194 static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
195 void *buffer, size_t *lenp, loff_t *ppos)
200 net = container_of(table->data, struct net,
201 ipv4.sysctl_ip_fwd_update_priority);
202 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
203 if (write && ret == 0)
204 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
210 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
211 void *buffer, size_t *lenp, loff_t *ppos)
213 struct net *net = container_of(ctl->data, struct net,
214 ipv4.tcp_congestion_control);
215 char val[TCP_CA_NAME_MAX];
216 struct ctl_table tbl = {
218 .maxlen = TCP_CA_NAME_MAX,
222 tcp_get_default_congestion_control(net, val);
224 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
225 if (write && ret == 0)
226 ret = tcp_set_default_congestion_control(net, val);
230 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
231 int write, void *buffer,
232 size_t *lenp, loff_t *ppos)
234 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
237 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
240 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
241 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
246 static int proc_allowed_congestion_control(struct ctl_table *ctl,
247 int write, void *buffer,
248 size_t *lenp, loff_t *ppos)
250 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
253 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
257 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
258 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
259 if (write && ret == 0)
260 ret = tcp_set_allowed_congestion_control(tbl.data);
265 static int sscanf_key(char *buf, __le32 *key)
270 if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
271 user_key + 2, user_key + 3) != 4) {
274 for (i = 0; i < ARRAY_SIZE(user_key); i++)
275 key[i] = cpu_to_le32(user_key[i]);
277 pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
278 user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);
283 static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
284 void *buffer, size_t *lenp, loff_t *ppos)
286 struct net *net = container_of(table->data, struct net,
287 ipv4.sysctl_tcp_fastopen);
288 /* maxlen to print the list of keys in hex (*2), with dashes
289 * separating doublewords and a comma in between keys.
291 struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
292 2 * TCP_FASTOPEN_KEY_MAX) +
293 (TCP_FASTOPEN_KEY_MAX * 5)) };
294 u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
295 __le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
297 int ret, i = 0, off = 0, n_keys;
299 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
303 n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
305 memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
309 for (i = 0; i < n_keys * 4; i++)
310 user_key[i] = le32_to_cpu(key[i]);
312 for (i = 0; i < n_keys; i++) {
313 off += snprintf(tbl.data + off, tbl.maxlen - off,
314 "%08x-%08x-%08x-%08x",
318 user_key[i * 4 + 3]);
320 if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
324 off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
327 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
329 if (write && ret == 0) {
330 backup_data = strchr(tbl.data, ',');
335 if (sscanf_key(tbl.data, key)) {
340 if (sscanf_key(backup_data, key + 4)) {
345 tcp_fastopen_reset_cipher(net, NULL, key,
346 backup_data ? key + 4 : NULL);
354 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
355 int write, void *buffer,
356 size_t *lenp, loff_t *ppos)
358 struct net *net = container_of(table->data, struct net,
359 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
362 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
363 if (write && ret == 0)
364 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
369 static int proc_tcp_available_ulp(struct ctl_table *ctl,
370 int write, void *buffer, size_t *lenp,
373 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
376 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
379 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
380 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
386 static int proc_tcp_ehash_entries(struct ctl_table *table, int write,
387 void *buffer, size_t *lenp, loff_t *ppos)
389 struct net *net = container_of(table->data, struct net,
390 ipv4.sysctl_tcp_child_ehash_entries);
391 struct inet_hashinfo *hinfo = net->ipv4.tcp_death_row.hashinfo;
392 int tcp_ehash_entries;
393 struct ctl_table tbl;
395 tcp_ehash_entries = hinfo->ehash_mask + 1;
397 /* A negative number indicates that the child netns
398 * shares the global ehash.
400 if (!net_eq(net, &init_net) && !hinfo->pernet)
401 tcp_ehash_entries *= -1;
403 tbl.data = &tcp_ehash_entries;
404 tbl.maxlen = sizeof(int);
406 return proc_dointvec(&tbl, write, buffer, lenp, ppos);
409 #ifdef CONFIG_IP_ROUTE_MULTIPATH
410 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
411 void *buffer, size_t *lenp,
414 struct net *net = container_of(table->data, struct net,
415 ipv4.sysctl_fib_multipath_hash_policy);
418 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
419 if (write && ret == 0)
420 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
425 static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write,
426 void *buffer, size_t *lenp,
432 net = container_of(table->data, struct net,
433 ipv4.sysctl_fib_multipath_hash_fields);
434 ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos);
435 if (write && ret == 0)
436 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
442 static struct ctl_table ipv4_table[] = {
444 .procname = "tcp_max_orphans",
445 .data = &sysctl_tcp_max_orphans,
446 .maxlen = sizeof(int),
448 .proc_handler = proc_dointvec
451 .procname = "inet_peer_threshold",
452 .data = &inet_peer_threshold,
453 .maxlen = sizeof(int),
455 .proc_handler = proc_dointvec
458 .procname = "inet_peer_minttl",
459 .data = &inet_peer_minttl,
460 .maxlen = sizeof(int),
462 .proc_handler = proc_dointvec_jiffies,
465 .procname = "inet_peer_maxttl",
466 .data = &inet_peer_maxttl,
467 .maxlen = sizeof(int),
469 .proc_handler = proc_dointvec_jiffies,
472 .procname = "tcp_mem",
473 .maxlen = sizeof(sysctl_tcp_mem),
474 .data = &sysctl_tcp_mem,
476 .proc_handler = proc_doulongvec_minmax,
479 .procname = "tcp_low_latency",
480 .data = &sysctl_tcp_low_latency,
481 .maxlen = sizeof(int),
483 .proc_handler = proc_dointvec
485 #ifdef CONFIG_NETLABEL
487 .procname = "cipso_cache_enable",
488 .data = &cipso_v4_cache_enabled,
489 .maxlen = sizeof(int),
491 .proc_handler = proc_dointvec,
494 .procname = "cipso_cache_bucket_size",
495 .data = &cipso_v4_cache_bucketsize,
496 .maxlen = sizeof(int),
498 .proc_handler = proc_dointvec,
501 .procname = "cipso_rbm_optfmt",
502 .data = &cipso_v4_rbm_optfmt,
503 .maxlen = sizeof(int),
505 .proc_handler = proc_dointvec,
508 .procname = "cipso_rbm_strictvalid",
509 .data = &cipso_v4_rbm_strictvalid,
510 .maxlen = sizeof(int),
512 .proc_handler = proc_dointvec,
514 #endif /* CONFIG_NETLABEL */
516 .procname = "tcp_available_ulp",
517 .maxlen = TCP_ULP_BUF_MAX,
519 .proc_handler = proc_tcp_available_ulp,
522 .procname = "icmp_msgs_per_sec",
523 .data = &sysctl_icmp_msgs_per_sec,
524 .maxlen = sizeof(int),
526 .proc_handler = proc_dointvec_minmax,
527 .extra1 = SYSCTL_ZERO,
530 .procname = "icmp_msgs_burst",
531 .data = &sysctl_icmp_msgs_burst,
532 .maxlen = sizeof(int),
534 .proc_handler = proc_dointvec_minmax,
535 .extra1 = SYSCTL_ZERO,
538 .procname = "udp_mem",
539 .data = &sysctl_udp_mem,
540 .maxlen = sizeof(sysctl_udp_mem),
542 .proc_handler = proc_doulongvec_minmax,
545 .procname = "fib_sync_mem",
546 .data = &sysctl_fib_sync_mem,
547 .maxlen = sizeof(sysctl_fib_sync_mem),
549 .proc_handler = proc_douintvec_minmax,
550 .extra1 = &sysctl_fib_sync_mem_min,
551 .extra2 = &sysctl_fib_sync_mem_max,
556 static struct ctl_table ipv4_net_table[] = {
558 .procname = "tcp_max_tw_buckets",
559 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
560 .maxlen = sizeof(int),
562 .proc_handler = proc_dointvec
565 .procname = "icmp_echo_ignore_all",
566 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
567 .maxlen = sizeof(u8),
569 .proc_handler = proc_dou8vec_minmax,
570 .extra1 = SYSCTL_ZERO,
574 .procname = "icmp_echo_enable_probe",
575 .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
576 .maxlen = sizeof(u8),
578 .proc_handler = proc_dou8vec_minmax,
579 .extra1 = SYSCTL_ZERO,
583 .procname = "icmp_echo_ignore_broadcasts",
584 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
585 .maxlen = sizeof(u8),
587 .proc_handler = proc_dou8vec_minmax,
588 .extra1 = SYSCTL_ZERO,
592 .procname = "icmp_ignore_bogus_error_responses",
593 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
594 .maxlen = sizeof(u8),
596 .proc_handler = proc_dou8vec_minmax,
597 .extra1 = SYSCTL_ZERO,
601 .procname = "icmp_errors_use_inbound_ifaddr",
602 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
603 .maxlen = sizeof(u8),
605 .proc_handler = proc_dou8vec_minmax,
606 .extra1 = SYSCTL_ZERO,
610 .procname = "icmp_ratelimit",
611 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
612 .maxlen = sizeof(int),
614 .proc_handler = proc_dointvec_ms_jiffies,
617 .procname = "icmp_ratemask",
618 .data = &init_net.ipv4.sysctl_icmp_ratemask,
619 .maxlen = sizeof(int),
621 .proc_handler = proc_dointvec
624 .procname = "ping_group_range",
625 .data = &init_net.ipv4.ping_group_range.range,
626 .maxlen = sizeof(gid_t)*2,
628 .proc_handler = ipv4_ping_group_range,
630 #ifdef CONFIG_NET_L3_MASTER_DEV
632 .procname = "raw_l3mdev_accept",
633 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
634 .maxlen = sizeof(u8),
636 .proc_handler = proc_dou8vec_minmax,
637 .extra1 = SYSCTL_ZERO,
638 .extra2 = SYSCTL_ONE,
642 .procname = "tcp_ecn",
643 .data = &init_net.ipv4.sysctl_tcp_ecn,
644 .maxlen = sizeof(u8),
646 .proc_handler = proc_dou8vec_minmax,
647 .extra1 = SYSCTL_ZERO,
648 .extra2 = SYSCTL_TWO,
651 .procname = "tcp_ecn_fallback",
652 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
653 .maxlen = sizeof(u8),
655 .proc_handler = proc_dou8vec_minmax,
656 .extra1 = SYSCTL_ZERO,
657 .extra2 = SYSCTL_ONE,
660 .procname = "ip_dynaddr",
661 .data = &init_net.ipv4.sysctl_ip_dynaddr,
662 .maxlen = sizeof(u8),
664 .proc_handler = proc_dou8vec_minmax,
667 .procname = "ip_early_demux",
668 .data = &init_net.ipv4.sysctl_ip_early_demux,
669 .maxlen = sizeof(u8),
671 .proc_handler = proc_dou8vec_minmax,
674 .procname = "udp_early_demux",
675 .data = &init_net.ipv4.sysctl_udp_early_demux,
676 .maxlen = sizeof(u8),
678 .proc_handler = proc_dou8vec_minmax,
681 .procname = "tcp_early_demux",
682 .data = &init_net.ipv4.sysctl_tcp_early_demux,
683 .maxlen = sizeof(u8),
685 .proc_handler = proc_dou8vec_minmax,
688 .procname = "nexthop_compat_mode",
689 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
690 .maxlen = sizeof(u8),
692 .proc_handler = proc_dou8vec_minmax,
693 .extra1 = SYSCTL_ZERO,
694 .extra2 = SYSCTL_ONE,
697 .procname = "ip_default_ttl",
698 .data = &init_net.ipv4.sysctl_ip_default_ttl,
699 .maxlen = sizeof(u8),
701 .proc_handler = proc_dou8vec_minmax,
702 .extra1 = &ip_ttl_min,
703 .extra2 = &ip_ttl_max,
706 .procname = "ip_local_port_range",
707 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
708 .data = &init_net.ipv4.ip_local_ports.range,
710 .proc_handler = ipv4_local_port_range,
713 .procname = "ip_local_reserved_ports",
714 .data = &init_net.ipv4.sysctl_local_reserved_ports,
717 .proc_handler = proc_do_large_bitmap,
720 .procname = "ip_no_pmtu_disc",
721 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
722 .maxlen = sizeof(u8),
724 .proc_handler = proc_dou8vec_minmax,
727 .procname = "ip_forward_use_pmtu",
728 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
729 .maxlen = sizeof(u8),
731 .proc_handler = proc_dou8vec_minmax,
734 .procname = "ip_forward_update_priority",
735 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
736 .maxlen = sizeof(u8),
738 .proc_handler = ipv4_fwd_update_priority,
739 .extra1 = SYSCTL_ZERO,
740 .extra2 = SYSCTL_ONE,
743 .procname = "ip_nonlocal_bind",
744 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
745 .maxlen = sizeof(u8),
747 .proc_handler = proc_dou8vec_minmax,
750 .procname = "ip_autobind_reuse",
751 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
752 .maxlen = sizeof(u8),
754 .proc_handler = proc_dou8vec_minmax,
755 .extra1 = SYSCTL_ZERO,
756 .extra2 = SYSCTL_ONE,
759 .procname = "fwmark_reflect",
760 .data = &init_net.ipv4.sysctl_fwmark_reflect,
761 .maxlen = sizeof(u8),
763 .proc_handler = proc_dou8vec_minmax,
766 .procname = "tcp_fwmark_accept",
767 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
768 .maxlen = sizeof(u8),
770 .proc_handler = proc_dou8vec_minmax,
772 #ifdef CONFIG_NET_L3_MASTER_DEV
774 .procname = "tcp_l3mdev_accept",
775 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
776 .maxlen = sizeof(u8),
778 .proc_handler = proc_dou8vec_minmax,
779 .extra1 = SYSCTL_ZERO,
780 .extra2 = SYSCTL_ONE,
784 .procname = "tcp_mtu_probing",
785 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
786 .maxlen = sizeof(u8),
788 .proc_handler = proc_dou8vec_minmax,
791 .procname = "tcp_base_mss",
792 .data = &init_net.ipv4.sysctl_tcp_base_mss,
793 .maxlen = sizeof(int),
795 .proc_handler = proc_dointvec,
798 .procname = "tcp_min_snd_mss",
799 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
800 .maxlen = sizeof(int),
802 .proc_handler = proc_dointvec_minmax,
803 .extra1 = &tcp_min_snd_mss_min,
804 .extra2 = &tcp_min_snd_mss_max,
807 .procname = "tcp_mtu_probe_floor",
808 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
809 .maxlen = sizeof(int),
811 .proc_handler = proc_dointvec_minmax,
812 .extra1 = &tcp_min_snd_mss_min,
813 .extra2 = &tcp_min_snd_mss_max,
816 .procname = "tcp_probe_threshold",
817 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
818 .maxlen = sizeof(int),
820 .proc_handler = proc_dointvec,
823 .procname = "tcp_probe_interval",
824 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
825 .maxlen = sizeof(u32),
827 .proc_handler = proc_douintvec_minmax,
828 .extra2 = &u32_max_div_HZ,
831 .procname = "igmp_link_local_mcast_reports",
832 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
833 .maxlen = sizeof(u8),
835 .proc_handler = proc_dou8vec_minmax,
838 .procname = "igmp_max_memberships",
839 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
840 .maxlen = sizeof(int),
842 .proc_handler = proc_dointvec
845 .procname = "igmp_max_msf",
846 .data = &init_net.ipv4.sysctl_igmp_max_msf,
847 .maxlen = sizeof(int),
849 .proc_handler = proc_dointvec
851 #ifdef CONFIG_IP_MULTICAST
853 .procname = "igmp_qrv",
854 .data = &init_net.ipv4.sysctl_igmp_qrv,
855 .maxlen = sizeof(int),
857 .proc_handler = proc_dointvec_minmax,
862 .procname = "tcp_congestion_control",
863 .data = &init_net.ipv4.tcp_congestion_control,
865 .maxlen = TCP_CA_NAME_MAX,
866 .proc_handler = proc_tcp_congestion_control,
869 .procname = "tcp_available_congestion_control",
870 .maxlen = TCP_CA_BUF_MAX,
872 .proc_handler = proc_tcp_available_congestion_control,
875 .procname = "tcp_allowed_congestion_control",
876 .maxlen = TCP_CA_BUF_MAX,
878 .proc_handler = proc_allowed_congestion_control,
881 .procname = "tcp_keepalive_time",
882 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
883 .maxlen = sizeof(int),
885 .proc_handler = proc_dointvec_jiffies,
888 .procname = "tcp_keepalive_probes",
889 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
890 .maxlen = sizeof(u8),
892 .proc_handler = proc_dou8vec_minmax,
895 .procname = "tcp_keepalive_intvl",
896 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
897 .maxlen = sizeof(int),
899 .proc_handler = proc_dointvec_jiffies,
902 .procname = "tcp_syn_retries",
903 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
904 .maxlen = sizeof(u8),
906 .proc_handler = proc_dou8vec_minmax,
907 .extra1 = &tcp_syn_retries_min,
908 .extra2 = &tcp_syn_retries_max
911 .procname = "tcp_synack_retries",
912 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
913 .maxlen = sizeof(u8),
915 .proc_handler = proc_dou8vec_minmax,
917 #ifdef CONFIG_SYN_COOKIES
919 .procname = "tcp_syncookies",
920 .data = &init_net.ipv4.sysctl_tcp_syncookies,
921 .maxlen = sizeof(u8),
923 .proc_handler = proc_dou8vec_minmax,
927 .procname = "tcp_migrate_req",
928 .data = &init_net.ipv4.sysctl_tcp_migrate_req,
929 .maxlen = sizeof(u8),
931 .proc_handler = proc_dou8vec_minmax,
932 .extra1 = SYSCTL_ZERO,
936 .procname = "tcp_reordering",
937 .data = &init_net.ipv4.sysctl_tcp_reordering,
938 .maxlen = sizeof(int),
940 .proc_handler = proc_dointvec
943 .procname = "tcp_retries1",
944 .data = &init_net.ipv4.sysctl_tcp_retries1,
945 .maxlen = sizeof(u8),
947 .proc_handler = proc_dou8vec_minmax,
948 .extra2 = &tcp_retr1_max
951 .procname = "tcp_retries2",
952 .data = &init_net.ipv4.sysctl_tcp_retries2,
953 .maxlen = sizeof(u8),
955 .proc_handler = proc_dou8vec_minmax,
958 .procname = "tcp_orphan_retries",
959 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
960 .maxlen = sizeof(u8),
962 .proc_handler = proc_dou8vec_minmax,
965 .procname = "tcp_fin_timeout",
966 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
967 .maxlen = sizeof(int),
969 .proc_handler = proc_dointvec_jiffies,
972 .procname = "tcp_notsent_lowat",
973 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
974 .maxlen = sizeof(unsigned int),
976 .proc_handler = proc_douintvec,
979 .procname = "tcp_tw_reuse",
980 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
981 .maxlen = sizeof(u8),
983 .proc_handler = proc_dou8vec_minmax,
984 .extra1 = SYSCTL_ZERO,
985 .extra2 = SYSCTL_TWO,
988 .procname = "tcp_max_syn_backlog",
989 .data = &init_net.ipv4.sysctl_max_syn_backlog,
990 .maxlen = sizeof(int),
992 .proc_handler = proc_dointvec
995 .procname = "tcp_fastopen",
996 .data = &init_net.ipv4.sysctl_tcp_fastopen,
997 .maxlen = sizeof(int),
999 .proc_handler = proc_dointvec,
1002 .procname = "tcp_fastopen_key",
1004 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1005 /* maxlen to print the list of keys in hex (*2), with dashes
1006 * separating doublewords and a comma in between keys.
1008 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
1009 2 * TCP_FASTOPEN_KEY_MAX) +
1010 (TCP_FASTOPEN_KEY_MAX * 5)),
1011 .proc_handler = proc_tcp_fastopen_key,
1014 .procname = "tcp_fastopen_blackhole_timeout_sec",
1015 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1016 .maxlen = sizeof(int),
1018 .proc_handler = proc_tfo_blackhole_detect_timeout,
1019 .extra1 = SYSCTL_ZERO,
1021 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1023 .procname = "fib_multipath_use_neigh",
1024 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1025 .maxlen = sizeof(u8),
1027 .proc_handler = proc_dou8vec_minmax,
1028 .extra1 = SYSCTL_ZERO,
1029 .extra2 = SYSCTL_ONE,
1032 .procname = "fib_multipath_hash_policy",
1033 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1034 .maxlen = sizeof(u8),
1036 .proc_handler = proc_fib_multipath_hash_policy,
1037 .extra1 = SYSCTL_ZERO,
1038 .extra2 = SYSCTL_THREE,
1041 .procname = "fib_multipath_hash_fields",
1042 .data = &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1043 .maxlen = sizeof(u32),
1045 .proc_handler = proc_fib_multipath_hash_fields,
1046 .extra1 = SYSCTL_ONE,
1047 .extra2 = &fib_multipath_hash_fields_all_mask,
1051 .procname = "ip_unprivileged_port_start",
1052 .maxlen = sizeof(int),
1053 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1055 .proc_handler = ipv4_privileged_ports,
1057 #ifdef CONFIG_NET_L3_MASTER_DEV
1059 .procname = "udp_l3mdev_accept",
1060 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1061 .maxlen = sizeof(u8),
1063 .proc_handler = proc_dou8vec_minmax,
1064 .extra1 = SYSCTL_ZERO,
1065 .extra2 = SYSCTL_ONE,
1069 .procname = "tcp_sack",
1070 .data = &init_net.ipv4.sysctl_tcp_sack,
1071 .maxlen = sizeof(u8),
1073 .proc_handler = proc_dou8vec_minmax,
1076 .procname = "tcp_window_scaling",
1077 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1078 .maxlen = sizeof(u8),
1080 .proc_handler = proc_dou8vec_minmax,
1083 .procname = "tcp_timestamps",
1084 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1085 .maxlen = sizeof(u8),
1087 .proc_handler = proc_dou8vec_minmax,
1090 .procname = "tcp_early_retrans",
1091 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1092 .maxlen = sizeof(u8),
1094 .proc_handler = proc_dou8vec_minmax,
1095 .extra1 = SYSCTL_ZERO,
1096 .extra2 = SYSCTL_FOUR,
1099 .procname = "tcp_recovery",
1100 .data = &init_net.ipv4.sysctl_tcp_recovery,
1101 .maxlen = sizeof(u8),
1103 .proc_handler = proc_dou8vec_minmax,
1106 .procname = "tcp_thin_linear_timeouts",
1107 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1108 .maxlen = sizeof(u8),
1110 .proc_handler = proc_dou8vec_minmax,
1113 .procname = "tcp_slow_start_after_idle",
1114 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1115 .maxlen = sizeof(u8),
1117 .proc_handler = proc_dou8vec_minmax,
1120 .procname = "tcp_retrans_collapse",
1121 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1122 .maxlen = sizeof(u8),
1124 .proc_handler = proc_dou8vec_minmax,
1127 .procname = "tcp_stdurg",
1128 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1129 .maxlen = sizeof(u8),
1131 .proc_handler = proc_dou8vec_minmax,
1134 .procname = "tcp_rfc1337",
1135 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1136 .maxlen = sizeof(u8),
1138 .proc_handler = proc_dou8vec_minmax,
1141 .procname = "tcp_abort_on_overflow",
1142 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1143 .maxlen = sizeof(u8),
1145 .proc_handler = proc_dou8vec_minmax,
1148 .procname = "tcp_fack",
1149 .data = &init_net.ipv4.sysctl_tcp_fack,
1150 .maxlen = sizeof(u8),
1152 .proc_handler = proc_dou8vec_minmax,
1155 .procname = "tcp_max_reordering",
1156 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1157 .maxlen = sizeof(int),
1159 .proc_handler = proc_dointvec
1162 .procname = "tcp_dsack",
1163 .data = &init_net.ipv4.sysctl_tcp_dsack,
1164 .maxlen = sizeof(u8),
1166 .proc_handler = proc_dou8vec_minmax,
1169 .procname = "tcp_app_win",
1170 .data = &init_net.ipv4.sysctl_tcp_app_win,
1171 .maxlen = sizeof(u8),
1173 .proc_handler = proc_dou8vec_minmax,
1176 .procname = "tcp_adv_win_scale",
1177 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1178 .maxlen = sizeof(int),
1180 .proc_handler = proc_dointvec_minmax,
1181 .extra1 = &tcp_adv_win_scale_min,
1182 .extra2 = &tcp_adv_win_scale_max,
1185 .procname = "tcp_frto",
1186 .data = &init_net.ipv4.sysctl_tcp_frto,
1187 .maxlen = sizeof(u8),
1189 .proc_handler = proc_dou8vec_minmax,
1192 .procname = "tcp_no_metrics_save",
1193 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1194 .maxlen = sizeof(u8),
1196 .proc_handler = proc_dou8vec_minmax,
1199 .procname = "tcp_no_ssthresh_metrics_save",
1200 .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1201 .maxlen = sizeof(u8),
1203 .proc_handler = proc_dou8vec_minmax,
1204 .extra1 = SYSCTL_ZERO,
1205 .extra2 = SYSCTL_ONE,
1208 .procname = "tcp_moderate_rcvbuf",
1209 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1210 .maxlen = sizeof(u8),
1212 .proc_handler = proc_dou8vec_minmax,
1215 .procname = "tcp_tso_win_divisor",
1216 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1217 .maxlen = sizeof(u8),
1219 .proc_handler = proc_dou8vec_minmax,
1222 .procname = "tcp_workaround_signed_windows",
1223 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1224 .maxlen = sizeof(u8),
1226 .proc_handler = proc_dou8vec_minmax,
1229 .procname = "tcp_limit_output_bytes",
1230 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1231 .maxlen = sizeof(int),
1233 .proc_handler = proc_dointvec
1236 .procname = "tcp_challenge_ack_limit",
1237 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1238 .maxlen = sizeof(int),
1240 .proc_handler = proc_dointvec
1243 .procname = "tcp_min_tso_segs",
1244 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1245 .maxlen = sizeof(u8),
1247 .proc_handler = proc_dou8vec_minmax,
1248 .extra1 = SYSCTL_ONE,
1251 .procname = "tcp_tso_rtt_log",
1252 .data = &init_net.ipv4.sysctl_tcp_tso_rtt_log,
1253 .maxlen = sizeof(u8),
1255 .proc_handler = proc_dou8vec_minmax,
1258 .procname = "tcp_min_rtt_wlen",
1259 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1260 .maxlen = sizeof(int),
1262 .proc_handler = proc_dointvec_minmax,
1263 .extra1 = SYSCTL_ZERO,
1264 .extra2 = &one_day_secs
1267 .procname = "tcp_autocorking",
1268 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1269 .maxlen = sizeof(u8),
1271 .proc_handler = proc_dou8vec_minmax,
1272 .extra1 = SYSCTL_ZERO,
1273 .extra2 = SYSCTL_ONE,
1276 .procname = "tcp_invalid_ratelimit",
1277 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1278 .maxlen = sizeof(int),
1280 .proc_handler = proc_dointvec_ms_jiffies,
1283 .procname = "tcp_pacing_ss_ratio",
1284 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1285 .maxlen = sizeof(int),
1287 .proc_handler = proc_dointvec_minmax,
1288 .extra1 = SYSCTL_ZERO,
1289 .extra2 = SYSCTL_ONE_THOUSAND,
1292 .procname = "tcp_pacing_ca_ratio",
1293 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1294 .maxlen = sizeof(int),
1296 .proc_handler = proc_dointvec_minmax,
1297 .extra1 = SYSCTL_ZERO,
1298 .extra2 = SYSCTL_ONE_THOUSAND,
1301 .procname = "tcp_wmem",
1302 .data = &init_net.ipv4.sysctl_tcp_wmem,
1303 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1305 .proc_handler = proc_dointvec_minmax,
1306 .extra1 = SYSCTL_ONE,
1309 .procname = "tcp_rmem",
1310 .data = &init_net.ipv4.sysctl_tcp_rmem,
1311 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1313 .proc_handler = proc_dointvec_minmax,
1314 .extra1 = SYSCTL_ONE,
1317 .procname = "tcp_comp_sack_delay_ns",
1318 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1319 .maxlen = sizeof(unsigned long),
1321 .proc_handler = proc_doulongvec_minmax,
1324 .procname = "tcp_comp_sack_slack_ns",
1325 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1326 .maxlen = sizeof(unsigned long),
1328 .proc_handler = proc_doulongvec_minmax,
1331 .procname = "tcp_comp_sack_nr",
1332 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1333 .maxlen = sizeof(u8),
1335 .proc_handler = proc_dou8vec_minmax,
1336 .extra1 = SYSCTL_ZERO,
1339 .procname = "tcp_reflect_tos",
1340 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1341 .maxlen = sizeof(u8),
1343 .proc_handler = proc_dou8vec_minmax,
1344 .extra1 = SYSCTL_ZERO,
1345 .extra2 = SYSCTL_ONE,
1348 .procname = "tcp_ehash_entries",
1349 .data = &init_net.ipv4.sysctl_tcp_child_ehash_entries,
1351 .proc_handler = proc_tcp_ehash_entries,
1354 .procname = "tcp_child_ehash_entries",
1355 .data = &init_net.ipv4.sysctl_tcp_child_ehash_entries,
1356 .maxlen = sizeof(unsigned int),
1358 .proc_handler = proc_douintvec_minmax,
1359 .extra1 = SYSCTL_ZERO,
1360 .extra2 = &tcp_child_ehash_entries_max,
1363 .procname = "udp_rmem_min",
1364 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1365 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1367 .proc_handler = proc_dointvec_minmax,
1368 .extra1 = SYSCTL_ONE
1371 .procname = "udp_wmem_min",
1372 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1373 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1375 .proc_handler = proc_dointvec_minmax,
1376 .extra1 = SYSCTL_ONE
1379 .procname = "fib_notify_on_flag_change",
1380 .data = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1381 .maxlen = sizeof(u8),
1383 .proc_handler = proc_dou8vec_minmax,
1384 .extra1 = SYSCTL_ZERO,
1385 .extra2 = SYSCTL_TWO,
1390 static __net_init int ipv4_sysctl_init_net(struct net *net)
1392 struct ctl_table *table;
1394 table = ipv4_net_table;
1395 if (!net_eq(net, &init_net)) {
1398 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1402 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1403 if (table[i].data) {
1404 /* Update the variables to point into
1405 * the current struct net
1407 table[i].data += (void *)net - (void *)&init_net;
1409 /* Entries without data pointer are global;
1410 * Make them read-only in non-init_net ns
1412 table[i].mode &= ~0222;
1417 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1418 if (!net->ipv4.ipv4_hdr)
1421 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1422 if (!net->ipv4.sysctl_local_reserved_ports)
1428 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1430 if (!net_eq(net, &init_net))
1436 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1438 struct ctl_table *table;
1440 kfree(net->ipv4.sysctl_local_reserved_ports);
1441 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1442 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1446 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1447 .init = ipv4_sysctl_init_net,
1448 .exit = ipv4_sysctl_exit_net,
1451 static __init int sysctl_ipv4_init(void)
1453 struct ctl_table_header *hdr;
1455 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1459 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1460 unregister_net_sysctl_table(hdr);
1467 __initcall(sysctl_ipv4_init);