1 // SPDX-License-Identifier: GPL-2.0
3 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
5 * Begun April 1, 1996, Mike Shaver.
6 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
10 #include <linux/module.h>
11 #include <linux/sysctl.h>
12 #include <linux/igmp.h>
13 #include <linux/inetdevice.h>
14 #include <linux/seqlock.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/nsproxy.h>
18 #include <linux/swap.h>
22 #include <net/ip_fib.h>
23 #include <net/route.h>
26 #include <net/cipso_ipv4.h>
27 #include <net/inet_frag.h>
29 #include <net/protocol.h>
30 #include <net/netevent.h>
33 static int three __maybe_unused = 3;
35 static int thousand = 1000;
36 static int tcp_retr1_max = 255;
37 static int ip_local_port_range_min[] = { 1, 1 };
38 static int ip_local_port_range_max[] = { 65535, 65535 };
39 static int tcp_adv_win_scale_min = -31;
40 static int tcp_adv_win_scale_max = 31;
41 static int tcp_app_win_max = 31;
42 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
43 static int tcp_min_snd_mss_max = 65535;
44 static int ip_privileged_port_min;
45 static int ip_privileged_port_max = 65535;
46 static int ip_ttl_min = 1;
47 static int ip_ttl_max = 255;
48 static int tcp_syn_retries_min = 1;
49 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
50 static int ip_ping_group_range_min[] = { 0, 0 };
51 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
52 static u32 u32_max_div_HZ = UINT_MAX / HZ;
53 static int one_day_secs = 24 * 3600;
54 static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
55 FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
58 static int sysctl_tcp_low_latency __read_mostly;
60 /* Update system visible IP port range */
61 static void set_local_port_range(struct net *net, int range[2])
63 bool same_parity = !((range[0] ^ range[1]) & 1);
65 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
66 if (same_parity && !net->ipv4.ip_local_ports.warned) {
67 net->ipv4.ip_local_ports.warned = true;
68 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
70 net->ipv4.ip_local_ports.range[0] = range[0];
71 net->ipv4.ip_local_ports.range[1] = range[1];
72 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
75 /* Validate changes from /proc interface. */
76 static int ipv4_local_port_range(struct ctl_table *table, int write,
77 void *buffer, size_t *lenp, loff_t *ppos)
80 container_of(table->data, struct net, ipv4.ip_local_ports.range);
83 struct ctl_table tmp = {
85 .maxlen = sizeof(range),
87 .extra1 = &ip_local_port_range_min,
88 .extra2 = &ip_local_port_range_max,
91 inet_get_local_port_range(net, &range[0], &range[1]);
93 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
95 if (write && ret == 0) {
96 /* Ensure that the upper limit is not smaller than the lower,
97 * and that the lower does not encroach upon the privileged
100 if ((range[1] < range[0]) ||
101 (range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock)))
104 set_local_port_range(net, range);
110 /* Validate changes from /proc interface. */
111 static int ipv4_privileged_ports(struct ctl_table *table, int write,
112 void *buffer, size_t *lenp, loff_t *ppos)
114 struct net *net = container_of(table->data, struct net,
115 ipv4.sysctl_ip_prot_sock);
119 struct ctl_table tmp = {
121 .maxlen = sizeof(pports),
123 .extra1 = &ip_privileged_port_min,
124 .extra2 = &ip_privileged_port_max,
127 pports = READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
129 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
131 if (write && ret == 0) {
132 inet_get_local_port_range(net, &range[0], &range[1]);
133 /* Ensure that the local port range doesn't overlap with the
134 * privileged port range.
136 if (range[0] < pports)
139 WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports);
145 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
147 kgid_t *data = table->data;
149 container_of(table->data, struct net, ipv4.ping_group_range.range);
152 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
156 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
159 /* Update system visible IP port range */
160 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
162 kgid_t *data = table->data;
164 container_of(table->data, struct net, ipv4.ping_group_range.range);
165 write_seqlock(&net->ipv4.ping_group_range.lock);
168 write_sequnlock(&net->ipv4.ping_group_range.lock);
171 /* Validate changes from /proc interface. */
172 static int ipv4_ping_group_range(struct ctl_table *table, int write,
173 void *buffer, size_t *lenp, loff_t *ppos)
175 struct user_namespace *user_ns = current_user_ns();
179 struct ctl_table tmp = {
181 .maxlen = sizeof(urange),
183 .extra1 = &ip_ping_group_range_min,
184 .extra2 = &ip_ping_group_range_max,
187 inet_get_ping_group_range_table(table, &low, &high);
188 urange[0] = from_kgid_munged(user_ns, low);
189 urange[1] = from_kgid_munged(user_ns, high);
190 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
192 if (write && ret == 0) {
193 low = make_kgid(user_ns, urange[0]);
194 high = make_kgid(user_ns, urange[1]);
195 if (!gid_valid(low) || !gid_valid(high))
197 if (urange[1] < urange[0] || gid_lt(high, low)) {
198 low = make_kgid(&init_user_ns, 1);
199 high = make_kgid(&init_user_ns, 0);
201 set_ping_group_range(table, low, high);
207 static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
208 void *buffer, size_t *lenp, loff_t *ppos)
213 net = container_of(table->data, struct net,
214 ipv4.sysctl_ip_fwd_update_priority);
215 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
216 if (write && ret == 0)
217 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
223 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
224 void *buffer, size_t *lenp, loff_t *ppos)
226 struct net *net = container_of(ctl->data, struct net,
227 ipv4.tcp_congestion_control);
228 char val[TCP_CA_NAME_MAX];
229 struct ctl_table tbl = {
231 .maxlen = TCP_CA_NAME_MAX,
235 tcp_get_default_congestion_control(net, val);
237 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
238 if (write && ret == 0)
239 ret = tcp_set_default_congestion_control(net, val);
243 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
244 int write, void *buffer,
245 size_t *lenp, loff_t *ppos)
247 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
250 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
253 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
254 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
259 static int proc_allowed_congestion_control(struct ctl_table *ctl,
260 int write, void *buffer,
261 size_t *lenp, loff_t *ppos)
263 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
266 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
270 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
271 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
272 if (write && ret == 0)
273 ret = tcp_set_allowed_congestion_control(tbl.data);
278 static int sscanf_key(char *buf, __le32 *key)
283 if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
284 user_key + 2, user_key + 3) != 4) {
287 for (i = 0; i < ARRAY_SIZE(user_key); i++)
288 key[i] = cpu_to_le32(user_key[i]);
290 pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
291 user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);
296 static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
297 void *buffer, size_t *lenp, loff_t *ppos)
299 struct net *net = container_of(table->data, struct net,
300 ipv4.sysctl_tcp_fastopen);
301 /* maxlen to print the list of keys in hex (*2), with dashes
302 * separating doublewords and a comma in between keys.
304 struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
305 2 * TCP_FASTOPEN_KEY_MAX) +
306 (TCP_FASTOPEN_KEY_MAX * 5)) };
307 u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
308 __le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
310 int ret, i = 0, off = 0, n_keys;
312 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
316 n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
318 memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
322 for (i = 0; i < n_keys * 4; i++)
323 user_key[i] = le32_to_cpu(key[i]);
325 for (i = 0; i < n_keys; i++) {
326 off += snprintf(tbl.data + off, tbl.maxlen - off,
327 "%08x-%08x-%08x-%08x",
331 user_key[i * 4 + 3]);
333 if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
337 off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
340 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
342 if (write && ret == 0) {
343 backup_data = strchr(tbl.data, ',');
348 if (sscanf_key(tbl.data, key)) {
353 if (sscanf_key(backup_data, key + 4)) {
358 tcp_fastopen_reset_cipher(net, NULL, key,
359 backup_data ? key + 4 : NULL);
367 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
368 int write, void *buffer,
369 size_t *lenp, loff_t *ppos)
371 struct net *net = container_of(table->data, struct net,
372 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
375 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
376 if (write && ret == 0)
377 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
382 static int proc_tcp_available_ulp(struct ctl_table *ctl,
383 int write, void *buffer, size_t *lenp,
386 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
389 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
392 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
393 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
399 #ifdef CONFIG_IP_ROUTE_MULTIPATH
400 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
401 void *buffer, size_t *lenp,
404 struct net *net = container_of(table->data, struct net,
405 ipv4.sysctl_fib_multipath_hash_policy);
408 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
409 if (write && ret == 0)
410 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
415 static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write,
416 void *buffer, size_t *lenp,
422 net = container_of(table->data, struct net,
423 ipv4.sysctl_fib_multipath_hash_fields);
424 ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos);
425 if (write && ret == 0)
426 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
432 static struct ctl_table ipv4_table[] = {
434 .procname = "tcp_max_orphans",
435 .data = &sysctl_tcp_max_orphans,
436 .maxlen = sizeof(int),
438 .proc_handler = proc_dointvec
441 .procname = "inet_peer_threshold",
442 .data = &inet_peer_threshold,
443 .maxlen = sizeof(int),
445 .proc_handler = proc_dointvec
448 .procname = "inet_peer_minttl",
449 .data = &inet_peer_minttl,
450 .maxlen = sizeof(int),
452 .proc_handler = proc_dointvec_jiffies,
455 .procname = "inet_peer_maxttl",
456 .data = &inet_peer_maxttl,
457 .maxlen = sizeof(int),
459 .proc_handler = proc_dointvec_jiffies,
462 .procname = "tcp_mem",
463 .maxlen = sizeof(sysctl_tcp_mem),
464 .data = &sysctl_tcp_mem,
466 .proc_handler = proc_doulongvec_minmax,
469 .procname = "tcp_low_latency",
470 .data = &sysctl_tcp_low_latency,
471 .maxlen = sizeof(int),
473 .proc_handler = proc_dointvec
475 #ifdef CONFIG_NETLABEL
477 .procname = "cipso_cache_enable",
478 .data = &cipso_v4_cache_enabled,
479 .maxlen = sizeof(int),
481 .proc_handler = proc_dointvec,
484 .procname = "cipso_cache_bucket_size",
485 .data = &cipso_v4_cache_bucketsize,
486 .maxlen = sizeof(int),
488 .proc_handler = proc_dointvec,
491 .procname = "cipso_rbm_optfmt",
492 .data = &cipso_v4_rbm_optfmt,
493 .maxlen = sizeof(int),
495 .proc_handler = proc_dointvec,
498 .procname = "cipso_rbm_strictvalid",
499 .data = &cipso_v4_rbm_strictvalid,
500 .maxlen = sizeof(int),
502 .proc_handler = proc_dointvec,
504 #endif /* CONFIG_NETLABEL */
506 .procname = "tcp_available_ulp",
507 .maxlen = TCP_ULP_BUF_MAX,
509 .proc_handler = proc_tcp_available_ulp,
512 .procname = "icmp_msgs_per_sec",
513 .data = &sysctl_icmp_msgs_per_sec,
514 .maxlen = sizeof(int),
516 .proc_handler = proc_dointvec_minmax,
517 .extra1 = SYSCTL_ZERO,
520 .procname = "icmp_msgs_burst",
521 .data = &sysctl_icmp_msgs_burst,
522 .maxlen = sizeof(int),
524 .proc_handler = proc_dointvec_minmax,
525 .extra1 = SYSCTL_ZERO,
528 .procname = "udp_mem",
529 .data = &sysctl_udp_mem,
530 .maxlen = sizeof(sysctl_udp_mem),
532 .proc_handler = proc_doulongvec_minmax,
535 .procname = "fib_sync_mem",
536 .data = &sysctl_fib_sync_mem,
537 .maxlen = sizeof(sysctl_fib_sync_mem),
539 .proc_handler = proc_douintvec_minmax,
540 .extra1 = &sysctl_fib_sync_mem_min,
541 .extra2 = &sysctl_fib_sync_mem_max,
544 .procname = "tcp_rx_skb_cache",
545 .data = &tcp_rx_skb_cache_key.key,
547 .proc_handler = proc_do_static_key,
550 .procname = "tcp_tx_skb_cache",
551 .data = &tcp_tx_skb_cache_key.key,
553 .proc_handler = proc_do_static_key,
558 static struct ctl_table ipv4_net_table[] = {
560 .procname = "icmp_echo_ignore_all",
561 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
562 .maxlen = sizeof(u8),
564 .proc_handler = proc_dou8vec_minmax,
567 .procname = "icmp_echo_enable_probe",
568 .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
569 .maxlen = sizeof(u8),
571 .proc_handler = proc_dou8vec_minmax,
572 .extra1 = SYSCTL_ZERO,
576 .procname = "icmp_echo_ignore_broadcasts",
577 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
578 .maxlen = sizeof(u8),
580 .proc_handler = proc_dou8vec_minmax,
583 .procname = "icmp_ignore_bogus_error_responses",
584 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
585 .maxlen = sizeof(u8),
587 .proc_handler = proc_dou8vec_minmax,
588 .extra1 = SYSCTL_ZERO,
592 .procname = "icmp_errors_use_inbound_ifaddr",
593 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
594 .maxlen = sizeof(u8),
596 .proc_handler = proc_dou8vec_minmax,
597 .extra1 = SYSCTL_ZERO,
601 .procname = "icmp_ratelimit",
602 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
603 .maxlen = sizeof(int),
605 .proc_handler = proc_dointvec_ms_jiffies,
608 .procname = "icmp_ratemask",
609 .data = &init_net.ipv4.sysctl_icmp_ratemask,
610 .maxlen = sizeof(int),
612 .proc_handler = proc_dointvec
615 .procname = "ping_group_range",
616 .data = &init_net.ipv4.ping_group_range.range,
617 .maxlen = sizeof(gid_t)*2,
619 .proc_handler = ipv4_ping_group_range,
621 #ifdef CONFIG_NET_L3_MASTER_DEV
623 .procname = "raw_l3mdev_accept",
624 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
625 .maxlen = sizeof(u8),
627 .proc_handler = proc_dou8vec_minmax,
628 .extra1 = SYSCTL_ZERO,
629 .extra2 = SYSCTL_ONE,
633 .procname = "tcp_ecn",
634 .data = &init_net.ipv4.sysctl_tcp_ecn,
635 .maxlen = sizeof(u8),
637 .proc_handler = proc_dou8vec_minmax,
638 .extra1 = SYSCTL_ZERO,
639 .extra2 = SYSCTL_TWO,
642 .procname = "tcp_ecn_fallback",
643 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
644 .maxlen = sizeof(u8),
646 .proc_handler = proc_dou8vec_minmax,
647 .extra1 = SYSCTL_ZERO,
648 .extra2 = SYSCTL_ONE,
651 .procname = "ip_dynaddr",
652 .data = &init_net.ipv4.sysctl_ip_dynaddr,
653 .maxlen = sizeof(u8),
655 .proc_handler = proc_dou8vec_minmax,
658 .procname = "ip_early_demux",
659 .data = &init_net.ipv4.sysctl_ip_early_demux,
660 .maxlen = sizeof(u8),
662 .proc_handler = proc_dou8vec_minmax,
665 .procname = "udp_early_demux",
666 .data = &init_net.ipv4.sysctl_udp_early_demux,
667 .maxlen = sizeof(u8),
669 .proc_handler = proc_dou8vec_minmax,
672 .procname = "tcp_early_demux",
673 .data = &init_net.ipv4.sysctl_tcp_early_demux,
674 .maxlen = sizeof(u8),
676 .proc_handler = proc_dou8vec_minmax,
679 .procname = "nexthop_compat_mode",
680 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
681 .maxlen = sizeof(u8),
683 .proc_handler = proc_dou8vec_minmax,
684 .extra1 = SYSCTL_ZERO,
685 .extra2 = SYSCTL_ONE,
688 .procname = "ip_default_ttl",
689 .data = &init_net.ipv4.sysctl_ip_default_ttl,
690 .maxlen = sizeof(u8),
692 .proc_handler = proc_dou8vec_minmax,
693 .extra1 = &ip_ttl_min,
694 .extra2 = &ip_ttl_max,
697 .procname = "ip_local_port_range",
698 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
699 .data = &init_net.ipv4.ip_local_ports.range,
701 .proc_handler = ipv4_local_port_range,
704 .procname = "ip_local_reserved_ports",
705 .data = &init_net.ipv4.sysctl_local_reserved_ports,
708 .proc_handler = proc_do_large_bitmap,
711 .procname = "ip_no_pmtu_disc",
712 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
713 .maxlen = sizeof(u8),
715 .proc_handler = proc_dou8vec_minmax,
718 .procname = "ip_forward_use_pmtu",
719 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
720 .maxlen = sizeof(u8),
722 .proc_handler = proc_dou8vec_minmax,
725 .procname = "ip_forward_update_priority",
726 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
727 .maxlen = sizeof(u8),
729 .proc_handler = ipv4_fwd_update_priority,
730 .extra1 = SYSCTL_ZERO,
731 .extra2 = SYSCTL_ONE,
734 .procname = "ip_nonlocal_bind",
735 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
736 .maxlen = sizeof(u8),
738 .proc_handler = proc_dou8vec_minmax,
741 .procname = "ip_autobind_reuse",
742 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
743 .maxlen = sizeof(u8),
745 .proc_handler = proc_dou8vec_minmax,
746 .extra1 = SYSCTL_ZERO,
747 .extra2 = SYSCTL_ONE,
750 .procname = "fwmark_reflect",
751 .data = &init_net.ipv4.sysctl_fwmark_reflect,
752 .maxlen = sizeof(u8),
754 .proc_handler = proc_dou8vec_minmax,
757 .procname = "tcp_fwmark_accept",
758 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
759 .maxlen = sizeof(u8),
761 .proc_handler = proc_dou8vec_minmax,
763 #ifdef CONFIG_NET_L3_MASTER_DEV
765 .procname = "tcp_l3mdev_accept",
766 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
767 .maxlen = sizeof(u8),
769 .proc_handler = proc_dou8vec_minmax,
770 .extra1 = SYSCTL_ZERO,
771 .extra2 = SYSCTL_ONE,
775 .procname = "tcp_mtu_probing",
776 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
777 .maxlen = sizeof(u8),
779 .proc_handler = proc_dou8vec_minmax,
782 .procname = "tcp_base_mss",
783 .data = &init_net.ipv4.sysctl_tcp_base_mss,
784 .maxlen = sizeof(int),
786 .proc_handler = proc_dointvec,
789 .procname = "tcp_min_snd_mss",
790 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
791 .maxlen = sizeof(int),
793 .proc_handler = proc_dointvec_minmax,
794 .extra1 = &tcp_min_snd_mss_min,
795 .extra2 = &tcp_min_snd_mss_max,
798 .procname = "tcp_mtu_probe_floor",
799 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
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_probe_threshold",
808 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
809 .maxlen = sizeof(int),
811 .proc_handler = proc_dointvec,
814 .procname = "tcp_probe_interval",
815 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
816 .maxlen = sizeof(u32),
818 .proc_handler = proc_douintvec_minmax,
819 .extra2 = &u32_max_div_HZ,
822 .procname = "igmp_link_local_mcast_reports",
823 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
824 .maxlen = sizeof(u8),
826 .proc_handler = proc_dou8vec_minmax,
829 .procname = "igmp_max_memberships",
830 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
831 .maxlen = sizeof(int),
833 .proc_handler = proc_dointvec
836 .procname = "igmp_max_msf",
837 .data = &init_net.ipv4.sysctl_igmp_max_msf,
838 .maxlen = sizeof(int),
840 .proc_handler = proc_dointvec
842 #ifdef CONFIG_IP_MULTICAST
844 .procname = "igmp_qrv",
845 .data = &init_net.ipv4.sysctl_igmp_qrv,
846 .maxlen = sizeof(int),
848 .proc_handler = proc_dointvec_minmax,
853 .procname = "tcp_congestion_control",
854 .data = &init_net.ipv4.tcp_congestion_control,
856 .maxlen = TCP_CA_NAME_MAX,
857 .proc_handler = proc_tcp_congestion_control,
860 .procname = "tcp_available_congestion_control",
861 .maxlen = TCP_CA_BUF_MAX,
863 .proc_handler = proc_tcp_available_congestion_control,
866 .procname = "tcp_allowed_congestion_control",
867 .maxlen = TCP_CA_BUF_MAX,
869 .proc_handler = proc_allowed_congestion_control,
872 .procname = "tcp_keepalive_time",
873 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
874 .maxlen = sizeof(int),
876 .proc_handler = proc_dointvec_jiffies,
879 .procname = "tcp_keepalive_probes",
880 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
881 .maxlen = sizeof(u8),
883 .proc_handler = proc_dou8vec_minmax,
886 .procname = "tcp_keepalive_intvl",
887 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
888 .maxlen = sizeof(int),
890 .proc_handler = proc_dointvec_jiffies,
893 .procname = "tcp_syn_retries",
894 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
895 .maxlen = sizeof(u8),
897 .proc_handler = proc_dou8vec_minmax,
898 .extra1 = &tcp_syn_retries_min,
899 .extra2 = &tcp_syn_retries_max
902 .procname = "tcp_synack_retries",
903 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
904 .maxlen = sizeof(u8),
906 .proc_handler = proc_dou8vec_minmax,
908 #ifdef CONFIG_SYN_COOKIES
910 .procname = "tcp_syncookies",
911 .data = &init_net.ipv4.sysctl_tcp_syncookies,
912 .maxlen = sizeof(u8),
914 .proc_handler = proc_dou8vec_minmax,
918 .procname = "tcp_migrate_req",
919 .data = &init_net.ipv4.sysctl_tcp_migrate_req,
920 .maxlen = sizeof(u8),
922 .proc_handler = proc_dou8vec_minmax,
923 .extra1 = SYSCTL_ZERO,
927 .procname = "tcp_reordering",
928 .data = &init_net.ipv4.sysctl_tcp_reordering,
929 .maxlen = sizeof(int),
931 .proc_handler = proc_dointvec
934 .procname = "tcp_retries1",
935 .data = &init_net.ipv4.sysctl_tcp_retries1,
936 .maxlen = sizeof(u8),
938 .proc_handler = proc_dou8vec_minmax,
939 .extra2 = &tcp_retr1_max
942 .procname = "tcp_retries2",
943 .data = &init_net.ipv4.sysctl_tcp_retries2,
944 .maxlen = sizeof(u8),
946 .proc_handler = proc_dou8vec_minmax,
949 .procname = "tcp_orphan_retries",
950 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
951 .maxlen = sizeof(u8),
953 .proc_handler = proc_dou8vec_minmax,
956 .procname = "tcp_fin_timeout",
957 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
958 .maxlen = sizeof(int),
960 .proc_handler = proc_dointvec_jiffies,
963 .procname = "tcp_notsent_lowat",
964 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
965 .maxlen = sizeof(unsigned int),
967 .proc_handler = proc_douintvec,
970 .procname = "tcp_tw_reuse",
971 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
972 .maxlen = sizeof(u8),
974 .proc_handler = proc_dou8vec_minmax,
975 .extra1 = SYSCTL_ZERO,
979 .procname = "tcp_max_tw_buckets",
980 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
981 .maxlen = sizeof(int),
983 .proc_handler = proc_dointvec
986 .procname = "tcp_max_syn_backlog",
987 .data = &init_net.ipv4.sysctl_max_syn_backlog,
988 .maxlen = sizeof(int),
990 .proc_handler = proc_dointvec
993 .procname = "tcp_fastopen",
994 .data = &init_net.ipv4.sysctl_tcp_fastopen,
995 .maxlen = sizeof(int),
997 .proc_handler = proc_dointvec,
1000 .procname = "tcp_fastopen_key",
1002 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1003 /* maxlen to print the list of keys in hex (*2), with dashes
1004 * separating doublewords and a comma in between keys.
1006 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
1007 2 * TCP_FASTOPEN_KEY_MAX) +
1008 (TCP_FASTOPEN_KEY_MAX * 5)),
1009 .proc_handler = proc_tcp_fastopen_key,
1012 .procname = "tcp_fastopen_blackhole_timeout_sec",
1013 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1014 .maxlen = sizeof(int),
1016 .proc_handler = proc_tfo_blackhole_detect_timeout,
1017 .extra1 = SYSCTL_ZERO,
1019 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1021 .procname = "fib_multipath_use_neigh",
1022 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1023 .maxlen = sizeof(u8),
1025 .proc_handler = proc_dou8vec_minmax,
1026 .extra1 = SYSCTL_ZERO,
1027 .extra2 = SYSCTL_ONE,
1030 .procname = "fib_multipath_hash_policy",
1031 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1032 .maxlen = sizeof(u8),
1034 .proc_handler = proc_fib_multipath_hash_policy,
1035 .extra1 = SYSCTL_ZERO,
1039 .procname = "fib_multipath_hash_fields",
1040 .data = &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1041 .maxlen = sizeof(u32),
1043 .proc_handler = proc_fib_multipath_hash_fields,
1044 .extra1 = SYSCTL_ONE,
1045 .extra2 = &fib_multipath_hash_fields_all_mask,
1049 .procname = "ip_unprivileged_port_start",
1050 .maxlen = sizeof(int),
1051 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1053 .proc_handler = ipv4_privileged_ports,
1055 #ifdef CONFIG_NET_L3_MASTER_DEV
1057 .procname = "udp_l3mdev_accept",
1058 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1059 .maxlen = sizeof(u8),
1061 .proc_handler = proc_dou8vec_minmax,
1062 .extra1 = SYSCTL_ZERO,
1063 .extra2 = SYSCTL_ONE,
1067 .procname = "tcp_sack",
1068 .data = &init_net.ipv4.sysctl_tcp_sack,
1069 .maxlen = sizeof(u8),
1071 .proc_handler = proc_dou8vec_minmax,
1074 .procname = "tcp_window_scaling",
1075 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1076 .maxlen = sizeof(u8),
1078 .proc_handler = proc_dou8vec_minmax,
1081 .procname = "tcp_timestamps",
1082 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1083 .maxlen = sizeof(u8),
1085 .proc_handler = proc_dou8vec_minmax,
1088 .procname = "tcp_early_retrans",
1089 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1090 .maxlen = sizeof(u8),
1092 .proc_handler = proc_dou8vec_minmax,
1093 .extra1 = SYSCTL_ZERO,
1097 .procname = "tcp_recovery",
1098 .data = &init_net.ipv4.sysctl_tcp_recovery,
1099 .maxlen = sizeof(u8),
1101 .proc_handler = proc_dou8vec_minmax,
1104 .procname = "tcp_thin_linear_timeouts",
1105 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1106 .maxlen = sizeof(u8),
1108 .proc_handler = proc_dou8vec_minmax,
1111 .procname = "tcp_slow_start_after_idle",
1112 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1113 .maxlen = sizeof(u8),
1115 .proc_handler = proc_dou8vec_minmax,
1118 .procname = "tcp_retrans_collapse",
1119 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1120 .maxlen = sizeof(u8),
1122 .proc_handler = proc_dou8vec_minmax,
1125 .procname = "tcp_stdurg",
1126 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1127 .maxlen = sizeof(u8),
1129 .proc_handler = proc_dou8vec_minmax,
1132 .procname = "tcp_rfc1337",
1133 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1134 .maxlen = sizeof(u8),
1136 .proc_handler = proc_dou8vec_minmax,
1139 .procname = "tcp_abort_on_overflow",
1140 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1141 .maxlen = sizeof(u8),
1143 .proc_handler = proc_dou8vec_minmax,
1146 .procname = "tcp_fack",
1147 .data = &init_net.ipv4.sysctl_tcp_fack,
1148 .maxlen = sizeof(u8),
1150 .proc_handler = proc_dou8vec_minmax,
1153 .procname = "tcp_max_reordering",
1154 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1155 .maxlen = sizeof(int),
1157 .proc_handler = proc_dointvec
1160 .procname = "tcp_dsack",
1161 .data = &init_net.ipv4.sysctl_tcp_dsack,
1162 .maxlen = sizeof(u8),
1164 .proc_handler = proc_dou8vec_minmax,
1167 .procname = "tcp_app_win",
1168 .data = &init_net.ipv4.sysctl_tcp_app_win,
1169 .maxlen = sizeof(u8),
1171 .proc_handler = proc_dou8vec_minmax,
1172 .extra1 = SYSCTL_ZERO,
1173 .extra2 = &tcp_app_win_max,
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_min_rtt_wlen",
1252 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1253 .maxlen = sizeof(int),
1255 .proc_handler = proc_dointvec_minmax,
1256 .extra1 = SYSCTL_ZERO,
1257 .extra2 = &one_day_secs
1260 .procname = "tcp_autocorking",
1261 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1262 .maxlen = sizeof(u8),
1264 .proc_handler = proc_dou8vec_minmax,
1265 .extra1 = SYSCTL_ZERO,
1266 .extra2 = SYSCTL_ONE,
1269 .procname = "tcp_invalid_ratelimit",
1270 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1271 .maxlen = sizeof(int),
1273 .proc_handler = proc_dointvec_ms_jiffies,
1276 .procname = "tcp_pacing_ss_ratio",
1277 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1278 .maxlen = sizeof(int),
1280 .proc_handler = proc_dointvec_minmax,
1281 .extra1 = SYSCTL_ZERO,
1282 .extra2 = &thousand,
1285 .procname = "tcp_pacing_ca_ratio",
1286 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1287 .maxlen = sizeof(int),
1289 .proc_handler = proc_dointvec_minmax,
1290 .extra1 = SYSCTL_ZERO,
1291 .extra2 = &thousand,
1294 .procname = "tcp_wmem",
1295 .data = &init_net.ipv4.sysctl_tcp_wmem,
1296 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1298 .proc_handler = proc_dointvec_minmax,
1299 .extra1 = SYSCTL_ONE,
1302 .procname = "tcp_rmem",
1303 .data = &init_net.ipv4.sysctl_tcp_rmem,
1304 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1306 .proc_handler = proc_dointvec_minmax,
1307 .extra1 = SYSCTL_ONE,
1310 .procname = "tcp_comp_sack_delay_ns",
1311 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1312 .maxlen = sizeof(unsigned long),
1314 .proc_handler = proc_doulongvec_minmax,
1317 .procname = "tcp_comp_sack_slack_ns",
1318 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1319 .maxlen = sizeof(unsigned long),
1321 .proc_handler = proc_doulongvec_minmax,
1324 .procname = "tcp_comp_sack_nr",
1325 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1326 .maxlen = sizeof(u8),
1328 .proc_handler = proc_dou8vec_minmax,
1329 .extra1 = SYSCTL_ZERO,
1332 .procname = "tcp_reflect_tos",
1333 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1334 .maxlen = sizeof(u8),
1336 .proc_handler = proc_dou8vec_minmax,
1337 .extra1 = SYSCTL_ZERO,
1338 .extra2 = SYSCTL_ONE,
1341 .procname = "udp_rmem_min",
1342 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1343 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1345 .proc_handler = proc_dointvec_minmax,
1346 .extra1 = SYSCTL_ONE
1349 .procname = "udp_wmem_min",
1350 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1351 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1353 .proc_handler = proc_dointvec_minmax,
1354 .extra1 = SYSCTL_ONE
1357 .procname = "fib_notify_on_flag_change",
1358 .data = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1359 .maxlen = sizeof(u8),
1361 .proc_handler = proc_dou8vec_minmax,
1362 .extra1 = SYSCTL_ZERO,
1368 static __net_init int ipv4_sysctl_init_net(struct net *net)
1370 struct ctl_table *table;
1372 table = ipv4_net_table;
1373 if (!net_eq(net, &init_net)) {
1376 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1380 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1381 if (table[i].data) {
1382 /* Update the variables to point into
1383 * the current struct net
1385 table[i].data += (void *)net - (void *)&init_net;
1387 /* Entries without data pointer are global;
1388 * Make them read-only in non-init_net ns
1390 table[i].mode &= ~0222;
1395 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1396 if (!net->ipv4.ipv4_hdr)
1399 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1400 if (!net->ipv4.sysctl_local_reserved_ports)
1406 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1408 if (!net_eq(net, &init_net))
1414 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1416 struct ctl_table *table;
1418 kfree(net->ipv4.sysctl_local_reserved_ports);
1419 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1420 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1424 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1425 .init = ipv4_sysctl_init_net,
1426 .exit = ipv4_sysctl_exit_net,
1429 static __init int sysctl_ipv4_init(void)
1431 struct ctl_table_header *hdr;
1433 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1437 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1438 unregister_net_sysctl_table(hdr);
1445 __initcall(sysctl_ipv4_init);