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_app_win_max = 31;
29 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
30 static int tcp_min_snd_mss_max = 65535;
31 static int ip_privileged_port_min;
32 static int ip_privileged_port_max = 65535;
33 static int ip_ttl_min = 1;
34 static int ip_ttl_max = 255;
35 static int tcp_syn_retries_min = 1;
36 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
37 static int ip_ping_group_range_min[] = { 0, 0 };
38 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
39 static u32 u32_max_div_HZ = UINT_MAX / HZ;
40 static int one_day_secs = 24 * 3600;
41 static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
42 FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
43 static unsigned int tcp_child_ehash_entries_max = 16 * 1024 * 1024;
46 static int sysctl_tcp_low_latency __read_mostly;
48 /* Update system visible IP port range */
49 static void set_local_port_range(struct net *net, int range[2])
51 bool same_parity = !((range[0] ^ range[1]) & 1);
53 write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
54 if (same_parity && !net->ipv4.ip_local_ports.warned) {
55 net->ipv4.ip_local_ports.warned = true;
56 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
58 net->ipv4.ip_local_ports.range[0] = range[0];
59 net->ipv4.ip_local_ports.range[1] = range[1];
60 write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
63 /* Validate changes from /proc interface. */
64 static int ipv4_local_port_range(struct ctl_table *table, int write,
65 void *buffer, size_t *lenp, loff_t *ppos)
68 container_of(table->data, struct net, ipv4.ip_local_ports.range);
71 struct ctl_table tmp = {
73 .maxlen = sizeof(range),
75 .extra1 = &ip_local_port_range_min,
76 .extra2 = &ip_local_port_range_max,
79 inet_get_local_port_range(net, &range[0], &range[1]);
81 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
83 if (write && ret == 0) {
84 /* Ensure that the upper limit is not smaller than the lower,
85 * and that the lower does not encroach upon the privileged
88 if ((range[1] < range[0]) ||
89 (range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock)))
92 set_local_port_range(net, range);
98 /* Validate changes from /proc interface. */
99 static int ipv4_privileged_ports(struct ctl_table *table, int write,
100 void *buffer, size_t *lenp, loff_t *ppos)
102 struct net *net = container_of(table->data, struct net,
103 ipv4.sysctl_ip_prot_sock);
107 struct ctl_table tmp = {
109 .maxlen = sizeof(pports),
111 .extra1 = &ip_privileged_port_min,
112 .extra2 = &ip_privileged_port_max,
115 pports = READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
117 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
119 if (write && ret == 0) {
120 inet_get_local_port_range(net, &range[0], &range[1]);
121 /* Ensure that the local port range doesn't overlap with the
122 * privileged port range.
124 if (range[0] < pports)
127 WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports);
133 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
135 kgid_t *data = table->data;
137 container_of(table->data, struct net, ipv4.ping_group_range.range);
140 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
144 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
147 /* Update system visible IP port range */
148 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
150 kgid_t *data = table->data;
152 container_of(table->data, struct net, ipv4.ping_group_range.range);
153 write_seqlock(&net->ipv4.ping_group_range.lock);
156 write_sequnlock(&net->ipv4.ping_group_range.lock);
159 /* Validate changes from /proc interface. */
160 static int ipv4_ping_group_range(struct ctl_table *table, int write,
161 void *buffer, size_t *lenp, loff_t *ppos)
163 struct user_namespace *user_ns = current_user_ns();
167 struct ctl_table tmp = {
169 .maxlen = sizeof(urange),
171 .extra1 = &ip_ping_group_range_min,
172 .extra2 = &ip_ping_group_range_max,
175 inet_get_ping_group_range_table(table, &low, &high);
176 urange[0] = from_kgid_munged(user_ns, low);
177 urange[1] = from_kgid_munged(user_ns, high);
178 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
180 if (write && ret == 0) {
181 low = make_kgid(user_ns, urange[0]);
182 high = make_kgid(user_ns, urange[1]);
183 if (!gid_valid(low) || !gid_valid(high))
185 if (urange[1] < urange[0] || gid_lt(high, low)) {
186 low = make_kgid(&init_user_ns, 1);
187 high = make_kgid(&init_user_ns, 0);
189 set_ping_group_range(table, low, high);
195 static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
196 void *buffer, size_t *lenp, loff_t *ppos)
201 net = container_of(table->data, struct net,
202 ipv4.sysctl_ip_fwd_update_priority);
203 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
204 if (write && ret == 0)
205 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
211 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
212 void *buffer, size_t *lenp, loff_t *ppos)
214 struct net *net = container_of(ctl->data, struct net,
215 ipv4.tcp_congestion_control);
216 char val[TCP_CA_NAME_MAX];
217 struct ctl_table tbl = {
219 .maxlen = TCP_CA_NAME_MAX,
223 tcp_get_default_congestion_control(net, val);
225 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
226 if (write && ret == 0)
227 ret = tcp_set_default_congestion_control(net, val);
231 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
232 int write, void *buffer,
233 size_t *lenp, loff_t *ppos)
235 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
238 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
241 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
242 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
247 static int proc_allowed_congestion_control(struct ctl_table *ctl,
248 int write, void *buffer,
249 size_t *lenp, loff_t *ppos)
251 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
254 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
258 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
259 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
260 if (write && ret == 0)
261 ret = tcp_set_allowed_congestion_control(tbl.data);
266 static int sscanf_key(char *buf, __le32 *key)
271 if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
272 user_key + 2, user_key + 3) != 4) {
275 for (i = 0; i < ARRAY_SIZE(user_key); i++)
276 key[i] = cpu_to_le32(user_key[i]);
278 pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
279 user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);
284 static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
285 void *buffer, size_t *lenp, loff_t *ppos)
287 struct net *net = container_of(table->data, struct net,
288 ipv4.sysctl_tcp_fastopen);
289 /* maxlen to print the list of keys in hex (*2), with dashes
290 * separating doublewords and a comma in between keys.
292 struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
293 2 * TCP_FASTOPEN_KEY_MAX) +
294 (TCP_FASTOPEN_KEY_MAX * 5)) };
295 u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
296 __le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
298 int ret, i = 0, off = 0, n_keys;
300 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
304 n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
306 memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
310 for (i = 0; i < n_keys * 4; i++)
311 user_key[i] = le32_to_cpu(key[i]);
313 for (i = 0; i < n_keys; i++) {
314 off += snprintf(tbl.data + off, tbl.maxlen - off,
315 "%08x-%08x-%08x-%08x",
319 user_key[i * 4 + 3]);
321 if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
325 off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
328 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
330 if (write && ret == 0) {
331 backup_data = strchr(tbl.data, ',');
336 if (sscanf_key(tbl.data, key)) {
341 if (sscanf_key(backup_data, key + 4)) {
346 tcp_fastopen_reset_cipher(net, NULL, key,
347 backup_data ? key + 4 : NULL);
355 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
356 int write, void *buffer,
357 size_t *lenp, loff_t *ppos)
359 struct net *net = container_of(table->data, struct net,
360 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
363 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
364 if (write && ret == 0)
365 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
370 static int proc_tcp_available_ulp(struct ctl_table *ctl,
371 int write, void *buffer, size_t *lenp,
374 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
377 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
380 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
381 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
387 static int proc_tcp_ehash_entries(struct ctl_table *table, int write,
388 void *buffer, size_t *lenp, loff_t *ppos)
390 struct net *net = container_of(table->data, struct net,
391 ipv4.sysctl_tcp_child_ehash_entries);
392 struct inet_hashinfo *hinfo = net->ipv4.tcp_death_row.hashinfo;
393 int tcp_ehash_entries;
394 struct ctl_table tbl;
396 tcp_ehash_entries = hinfo->ehash_mask + 1;
398 /* A negative number indicates that the child netns
399 * shares the global ehash.
401 if (!net_eq(net, &init_net) && !hinfo->pernet)
402 tcp_ehash_entries *= -1;
404 tbl.data = &tcp_ehash_entries;
405 tbl.maxlen = sizeof(int);
407 return proc_dointvec(&tbl, write, buffer, lenp, ppos);
410 #ifdef CONFIG_IP_ROUTE_MULTIPATH
411 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
412 void *buffer, size_t *lenp,
415 struct net *net = container_of(table->data, struct net,
416 ipv4.sysctl_fib_multipath_hash_policy);
419 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
420 if (write && ret == 0)
421 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
426 static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write,
427 void *buffer, size_t *lenp,
433 net = container_of(table->data, struct net,
434 ipv4.sysctl_fib_multipath_hash_fields);
435 ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos);
436 if (write && ret == 0)
437 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
443 static struct ctl_table ipv4_table[] = {
445 .procname = "tcp_max_orphans",
446 .data = &sysctl_tcp_max_orphans,
447 .maxlen = sizeof(int),
449 .proc_handler = proc_dointvec
452 .procname = "inet_peer_threshold",
453 .data = &inet_peer_threshold,
454 .maxlen = sizeof(int),
456 .proc_handler = proc_dointvec
459 .procname = "inet_peer_minttl",
460 .data = &inet_peer_minttl,
461 .maxlen = sizeof(int),
463 .proc_handler = proc_dointvec_jiffies,
466 .procname = "inet_peer_maxttl",
467 .data = &inet_peer_maxttl,
468 .maxlen = sizeof(int),
470 .proc_handler = proc_dointvec_jiffies,
473 .procname = "tcp_mem",
474 .maxlen = sizeof(sysctl_tcp_mem),
475 .data = &sysctl_tcp_mem,
477 .proc_handler = proc_doulongvec_minmax,
480 .procname = "tcp_low_latency",
481 .data = &sysctl_tcp_low_latency,
482 .maxlen = sizeof(int),
484 .proc_handler = proc_dointvec
486 #ifdef CONFIG_NETLABEL
488 .procname = "cipso_cache_enable",
489 .data = &cipso_v4_cache_enabled,
490 .maxlen = sizeof(int),
492 .proc_handler = proc_dointvec,
495 .procname = "cipso_cache_bucket_size",
496 .data = &cipso_v4_cache_bucketsize,
497 .maxlen = sizeof(int),
499 .proc_handler = proc_dointvec,
502 .procname = "cipso_rbm_optfmt",
503 .data = &cipso_v4_rbm_optfmt,
504 .maxlen = sizeof(int),
506 .proc_handler = proc_dointvec,
509 .procname = "cipso_rbm_strictvalid",
510 .data = &cipso_v4_rbm_strictvalid,
511 .maxlen = sizeof(int),
513 .proc_handler = proc_dointvec,
515 #endif /* CONFIG_NETLABEL */
517 .procname = "tcp_available_ulp",
518 .maxlen = TCP_ULP_BUF_MAX,
520 .proc_handler = proc_tcp_available_ulp,
523 .procname = "icmp_msgs_per_sec",
524 .data = &sysctl_icmp_msgs_per_sec,
525 .maxlen = sizeof(int),
527 .proc_handler = proc_dointvec_minmax,
528 .extra1 = SYSCTL_ZERO,
531 .procname = "icmp_msgs_burst",
532 .data = &sysctl_icmp_msgs_burst,
533 .maxlen = sizeof(int),
535 .proc_handler = proc_dointvec_minmax,
536 .extra1 = SYSCTL_ZERO,
539 .procname = "udp_mem",
540 .data = &sysctl_udp_mem,
541 .maxlen = sizeof(sysctl_udp_mem),
543 .proc_handler = proc_doulongvec_minmax,
546 .procname = "fib_sync_mem",
547 .data = &sysctl_fib_sync_mem,
548 .maxlen = sizeof(sysctl_fib_sync_mem),
550 .proc_handler = proc_douintvec_minmax,
551 .extra1 = &sysctl_fib_sync_mem_min,
552 .extra2 = &sysctl_fib_sync_mem_max,
557 static struct ctl_table ipv4_net_table[] = {
559 .procname = "tcp_max_tw_buckets",
560 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
561 .maxlen = sizeof(int),
563 .proc_handler = proc_dointvec
566 .procname = "icmp_echo_ignore_all",
567 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
568 .maxlen = sizeof(u8),
570 .proc_handler = proc_dou8vec_minmax,
571 .extra1 = SYSCTL_ZERO,
575 .procname = "icmp_echo_enable_probe",
576 .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
577 .maxlen = sizeof(u8),
579 .proc_handler = proc_dou8vec_minmax,
580 .extra1 = SYSCTL_ZERO,
584 .procname = "icmp_echo_ignore_broadcasts",
585 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
586 .maxlen = sizeof(u8),
588 .proc_handler = proc_dou8vec_minmax,
589 .extra1 = SYSCTL_ZERO,
593 .procname = "icmp_ignore_bogus_error_responses",
594 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
595 .maxlen = sizeof(u8),
597 .proc_handler = proc_dou8vec_minmax,
598 .extra1 = SYSCTL_ZERO,
602 .procname = "icmp_errors_use_inbound_ifaddr",
603 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
604 .maxlen = sizeof(u8),
606 .proc_handler = proc_dou8vec_minmax,
607 .extra1 = SYSCTL_ZERO,
611 .procname = "icmp_ratelimit",
612 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
613 .maxlen = sizeof(int),
615 .proc_handler = proc_dointvec_ms_jiffies,
618 .procname = "icmp_ratemask",
619 .data = &init_net.ipv4.sysctl_icmp_ratemask,
620 .maxlen = sizeof(int),
622 .proc_handler = proc_dointvec
625 .procname = "ping_group_range",
626 .data = &init_net.ipv4.ping_group_range.range,
627 .maxlen = sizeof(gid_t)*2,
629 .proc_handler = ipv4_ping_group_range,
631 #ifdef CONFIG_NET_L3_MASTER_DEV
633 .procname = "raw_l3mdev_accept",
634 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
635 .maxlen = sizeof(u8),
637 .proc_handler = proc_dou8vec_minmax,
638 .extra1 = SYSCTL_ZERO,
639 .extra2 = SYSCTL_ONE,
643 .procname = "tcp_ecn",
644 .data = &init_net.ipv4.sysctl_tcp_ecn,
645 .maxlen = sizeof(u8),
647 .proc_handler = proc_dou8vec_minmax,
648 .extra1 = SYSCTL_ZERO,
649 .extra2 = SYSCTL_TWO,
652 .procname = "tcp_ecn_fallback",
653 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
654 .maxlen = sizeof(u8),
656 .proc_handler = proc_dou8vec_minmax,
657 .extra1 = SYSCTL_ZERO,
658 .extra2 = SYSCTL_ONE,
661 .procname = "ip_dynaddr",
662 .data = &init_net.ipv4.sysctl_ip_dynaddr,
663 .maxlen = sizeof(u8),
665 .proc_handler = proc_dou8vec_minmax,
668 .procname = "ip_early_demux",
669 .data = &init_net.ipv4.sysctl_ip_early_demux,
670 .maxlen = sizeof(u8),
672 .proc_handler = proc_dou8vec_minmax,
675 .procname = "udp_early_demux",
676 .data = &init_net.ipv4.sysctl_udp_early_demux,
677 .maxlen = sizeof(u8),
679 .proc_handler = proc_dou8vec_minmax,
682 .procname = "tcp_early_demux",
683 .data = &init_net.ipv4.sysctl_tcp_early_demux,
684 .maxlen = sizeof(u8),
686 .proc_handler = proc_dou8vec_minmax,
689 .procname = "nexthop_compat_mode",
690 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
691 .maxlen = sizeof(u8),
693 .proc_handler = proc_dou8vec_minmax,
694 .extra1 = SYSCTL_ZERO,
695 .extra2 = SYSCTL_ONE,
698 .procname = "ip_default_ttl",
699 .data = &init_net.ipv4.sysctl_ip_default_ttl,
700 .maxlen = sizeof(u8),
702 .proc_handler = proc_dou8vec_minmax,
703 .extra1 = &ip_ttl_min,
704 .extra2 = &ip_ttl_max,
707 .procname = "ip_local_port_range",
708 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
709 .data = &init_net.ipv4.ip_local_ports.range,
711 .proc_handler = ipv4_local_port_range,
714 .procname = "ip_local_reserved_ports",
715 .data = &init_net.ipv4.sysctl_local_reserved_ports,
718 .proc_handler = proc_do_large_bitmap,
721 .procname = "ip_no_pmtu_disc",
722 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
723 .maxlen = sizeof(u8),
725 .proc_handler = proc_dou8vec_minmax,
728 .procname = "ip_forward_use_pmtu",
729 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
730 .maxlen = sizeof(u8),
732 .proc_handler = proc_dou8vec_minmax,
735 .procname = "ip_forward_update_priority",
736 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
737 .maxlen = sizeof(u8),
739 .proc_handler = ipv4_fwd_update_priority,
740 .extra1 = SYSCTL_ZERO,
741 .extra2 = SYSCTL_ONE,
744 .procname = "ip_nonlocal_bind",
745 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
746 .maxlen = sizeof(u8),
748 .proc_handler = proc_dou8vec_minmax,
751 .procname = "ip_autobind_reuse",
752 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
753 .maxlen = sizeof(u8),
755 .proc_handler = proc_dou8vec_minmax,
756 .extra1 = SYSCTL_ZERO,
757 .extra2 = SYSCTL_ONE,
760 .procname = "fwmark_reflect",
761 .data = &init_net.ipv4.sysctl_fwmark_reflect,
762 .maxlen = sizeof(u8),
764 .proc_handler = proc_dou8vec_minmax,
767 .procname = "tcp_fwmark_accept",
768 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
769 .maxlen = sizeof(u8),
771 .proc_handler = proc_dou8vec_minmax,
773 #ifdef CONFIG_NET_L3_MASTER_DEV
775 .procname = "tcp_l3mdev_accept",
776 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
777 .maxlen = sizeof(u8),
779 .proc_handler = proc_dou8vec_minmax,
780 .extra1 = SYSCTL_ZERO,
781 .extra2 = SYSCTL_ONE,
785 .procname = "tcp_mtu_probing",
786 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
787 .maxlen = sizeof(u8),
789 .proc_handler = proc_dou8vec_minmax,
792 .procname = "tcp_base_mss",
793 .data = &init_net.ipv4.sysctl_tcp_base_mss,
794 .maxlen = sizeof(int),
796 .proc_handler = proc_dointvec,
799 .procname = "tcp_min_snd_mss",
800 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
801 .maxlen = sizeof(int),
803 .proc_handler = proc_dointvec_minmax,
804 .extra1 = &tcp_min_snd_mss_min,
805 .extra2 = &tcp_min_snd_mss_max,
808 .procname = "tcp_mtu_probe_floor",
809 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
810 .maxlen = sizeof(int),
812 .proc_handler = proc_dointvec_minmax,
813 .extra1 = &tcp_min_snd_mss_min,
814 .extra2 = &tcp_min_snd_mss_max,
817 .procname = "tcp_probe_threshold",
818 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
819 .maxlen = sizeof(int),
821 .proc_handler = proc_dointvec,
824 .procname = "tcp_probe_interval",
825 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
826 .maxlen = sizeof(u32),
828 .proc_handler = proc_douintvec_minmax,
829 .extra2 = &u32_max_div_HZ,
832 .procname = "igmp_link_local_mcast_reports",
833 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
834 .maxlen = sizeof(u8),
836 .proc_handler = proc_dou8vec_minmax,
839 .procname = "igmp_max_memberships",
840 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
841 .maxlen = sizeof(int),
843 .proc_handler = proc_dointvec
846 .procname = "igmp_max_msf",
847 .data = &init_net.ipv4.sysctl_igmp_max_msf,
848 .maxlen = sizeof(int),
850 .proc_handler = proc_dointvec
852 #ifdef CONFIG_IP_MULTICAST
854 .procname = "igmp_qrv",
855 .data = &init_net.ipv4.sysctl_igmp_qrv,
856 .maxlen = sizeof(int),
858 .proc_handler = proc_dointvec_minmax,
863 .procname = "tcp_congestion_control",
864 .data = &init_net.ipv4.tcp_congestion_control,
866 .maxlen = TCP_CA_NAME_MAX,
867 .proc_handler = proc_tcp_congestion_control,
870 .procname = "tcp_available_congestion_control",
871 .maxlen = TCP_CA_BUF_MAX,
873 .proc_handler = proc_tcp_available_congestion_control,
876 .procname = "tcp_allowed_congestion_control",
877 .maxlen = TCP_CA_BUF_MAX,
879 .proc_handler = proc_allowed_congestion_control,
882 .procname = "tcp_keepalive_time",
883 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
884 .maxlen = sizeof(int),
886 .proc_handler = proc_dointvec_jiffies,
889 .procname = "tcp_keepalive_probes",
890 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
891 .maxlen = sizeof(u8),
893 .proc_handler = proc_dou8vec_minmax,
896 .procname = "tcp_keepalive_intvl",
897 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
898 .maxlen = sizeof(int),
900 .proc_handler = proc_dointvec_jiffies,
903 .procname = "tcp_syn_retries",
904 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
905 .maxlen = sizeof(u8),
907 .proc_handler = proc_dou8vec_minmax,
908 .extra1 = &tcp_syn_retries_min,
909 .extra2 = &tcp_syn_retries_max
912 .procname = "tcp_synack_retries",
913 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
914 .maxlen = sizeof(u8),
916 .proc_handler = proc_dou8vec_minmax,
918 #ifdef CONFIG_SYN_COOKIES
920 .procname = "tcp_syncookies",
921 .data = &init_net.ipv4.sysctl_tcp_syncookies,
922 .maxlen = sizeof(u8),
924 .proc_handler = proc_dou8vec_minmax,
928 .procname = "tcp_migrate_req",
929 .data = &init_net.ipv4.sysctl_tcp_migrate_req,
930 .maxlen = sizeof(u8),
932 .proc_handler = proc_dou8vec_minmax,
933 .extra1 = SYSCTL_ZERO,
937 .procname = "tcp_reordering",
938 .data = &init_net.ipv4.sysctl_tcp_reordering,
939 .maxlen = sizeof(int),
941 .proc_handler = proc_dointvec
944 .procname = "tcp_retries1",
945 .data = &init_net.ipv4.sysctl_tcp_retries1,
946 .maxlen = sizeof(u8),
948 .proc_handler = proc_dou8vec_minmax,
949 .extra2 = &tcp_retr1_max
952 .procname = "tcp_retries2",
953 .data = &init_net.ipv4.sysctl_tcp_retries2,
954 .maxlen = sizeof(u8),
956 .proc_handler = proc_dou8vec_minmax,
959 .procname = "tcp_orphan_retries",
960 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
961 .maxlen = sizeof(u8),
963 .proc_handler = proc_dou8vec_minmax,
966 .procname = "tcp_fin_timeout",
967 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
968 .maxlen = sizeof(int),
970 .proc_handler = proc_dointvec_jiffies,
973 .procname = "tcp_notsent_lowat",
974 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
975 .maxlen = sizeof(unsigned int),
977 .proc_handler = proc_douintvec,
980 .procname = "tcp_tw_reuse",
981 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
982 .maxlen = sizeof(u8),
984 .proc_handler = proc_dou8vec_minmax,
985 .extra1 = SYSCTL_ZERO,
986 .extra2 = SYSCTL_TWO,
989 .procname = "tcp_max_syn_backlog",
990 .data = &init_net.ipv4.sysctl_max_syn_backlog,
991 .maxlen = sizeof(int),
993 .proc_handler = proc_dointvec
996 .procname = "tcp_fastopen",
997 .data = &init_net.ipv4.sysctl_tcp_fastopen,
998 .maxlen = sizeof(int),
1000 .proc_handler = proc_dointvec,
1003 .procname = "tcp_fastopen_key",
1005 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1006 /* maxlen to print the list of keys in hex (*2), with dashes
1007 * separating doublewords and a comma in between keys.
1009 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
1010 2 * TCP_FASTOPEN_KEY_MAX) +
1011 (TCP_FASTOPEN_KEY_MAX * 5)),
1012 .proc_handler = proc_tcp_fastopen_key,
1015 .procname = "tcp_fastopen_blackhole_timeout_sec",
1016 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1017 .maxlen = sizeof(int),
1019 .proc_handler = proc_tfo_blackhole_detect_timeout,
1020 .extra1 = SYSCTL_ZERO,
1022 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1024 .procname = "fib_multipath_use_neigh",
1025 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1026 .maxlen = sizeof(u8),
1028 .proc_handler = proc_dou8vec_minmax,
1029 .extra1 = SYSCTL_ZERO,
1030 .extra2 = SYSCTL_ONE,
1033 .procname = "fib_multipath_hash_policy",
1034 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1035 .maxlen = sizeof(u8),
1037 .proc_handler = proc_fib_multipath_hash_policy,
1038 .extra1 = SYSCTL_ZERO,
1039 .extra2 = SYSCTL_THREE,
1042 .procname = "fib_multipath_hash_fields",
1043 .data = &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1044 .maxlen = sizeof(u32),
1046 .proc_handler = proc_fib_multipath_hash_fields,
1047 .extra1 = SYSCTL_ONE,
1048 .extra2 = &fib_multipath_hash_fields_all_mask,
1052 .procname = "ip_unprivileged_port_start",
1053 .maxlen = sizeof(int),
1054 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1056 .proc_handler = ipv4_privileged_ports,
1058 #ifdef CONFIG_NET_L3_MASTER_DEV
1060 .procname = "udp_l3mdev_accept",
1061 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1062 .maxlen = sizeof(u8),
1064 .proc_handler = proc_dou8vec_minmax,
1065 .extra1 = SYSCTL_ZERO,
1066 .extra2 = SYSCTL_ONE,
1070 .procname = "tcp_sack",
1071 .data = &init_net.ipv4.sysctl_tcp_sack,
1072 .maxlen = sizeof(u8),
1074 .proc_handler = proc_dou8vec_minmax,
1077 .procname = "tcp_window_scaling",
1078 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1079 .maxlen = sizeof(u8),
1081 .proc_handler = proc_dou8vec_minmax,
1084 .procname = "tcp_timestamps",
1085 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1086 .maxlen = sizeof(u8),
1088 .proc_handler = proc_dou8vec_minmax,
1091 .procname = "tcp_early_retrans",
1092 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1093 .maxlen = sizeof(u8),
1095 .proc_handler = proc_dou8vec_minmax,
1096 .extra1 = SYSCTL_ZERO,
1097 .extra2 = SYSCTL_FOUR,
1100 .procname = "tcp_recovery",
1101 .data = &init_net.ipv4.sysctl_tcp_recovery,
1102 .maxlen = sizeof(u8),
1104 .proc_handler = proc_dou8vec_minmax,
1107 .procname = "tcp_thin_linear_timeouts",
1108 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1109 .maxlen = sizeof(u8),
1111 .proc_handler = proc_dou8vec_minmax,
1114 .procname = "tcp_slow_start_after_idle",
1115 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1116 .maxlen = sizeof(u8),
1118 .proc_handler = proc_dou8vec_minmax,
1121 .procname = "tcp_retrans_collapse",
1122 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1123 .maxlen = sizeof(u8),
1125 .proc_handler = proc_dou8vec_minmax,
1128 .procname = "tcp_stdurg",
1129 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1130 .maxlen = sizeof(u8),
1132 .proc_handler = proc_dou8vec_minmax,
1135 .procname = "tcp_rfc1337",
1136 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1137 .maxlen = sizeof(u8),
1139 .proc_handler = proc_dou8vec_minmax,
1142 .procname = "tcp_abort_on_overflow",
1143 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1144 .maxlen = sizeof(u8),
1146 .proc_handler = proc_dou8vec_minmax,
1149 .procname = "tcp_fack",
1150 .data = &init_net.ipv4.sysctl_tcp_fack,
1151 .maxlen = sizeof(u8),
1153 .proc_handler = proc_dou8vec_minmax,
1156 .procname = "tcp_max_reordering",
1157 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1158 .maxlen = sizeof(int),
1160 .proc_handler = proc_dointvec
1163 .procname = "tcp_dsack",
1164 .data = &init_net.ipv4.sysctl_tcp_dsack,
1165 .maxlen = sizeof(u8),
1167 .proc_handler = proc_dou8vec_minmax,
1170 .procname = "tcp_app_win",
1171 .data = &init_net.ipv4.sysctl_tcp_app_win,
1172 .maxlen = sizeof(u8),
1174 .proc_handler = proc_dou8vec_minmax,
1175 .extra1 = SYSCTL_ZERO,
1176 .extra2 = &tcp_app_win_max,
1179 .procname = "tcp_adv_win_scale",
1180 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1181 .maxlen = sizeof(int),
1183 .proc_handler = proc_dointvec_minmax,
1184 .extra1 = &tcp_adv_win_scale_min,
1185 .extra2 = &tcp_adv_win_scale_max,
1188 .procname = "tcp_frto",
1189 .data = &init_net.ipv4.sysctl_tcp_frto,
1190 .maxlen = sizeof(u8),
1192 .proc_handler = proc_dou8vec_minmax,
1195 .procname = "tcp_no_metrics_save",
1196 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1197 .maxlen = sizeof(u8),
1199 .proc_handler = proc_dou8vec_minmax,
1202 .procname = "tcp_no_ssthresh_metrics_save",
1203 .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1204 .maxlen = sizeof(u8),
1206 .proc_handler = proc_dou8vec_minmax,
1207 .extra1 = SYSCTL_ZERO,
1208 .extra2 = SYSCTL_ONE,
1211 .procname = "tcp_moderate_rcvbuf",
1212 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1213 .maxlen = sizeof(u8),
1215 .proc_handler = proc_dou8vec_minmax,
1218 .procname = "tcp_tso_win_divisor",
1219 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1220 .maxlen = sizeof(u8),
1222 .proc_handler = proc_dou8vec_minmax,
1225 .procname = "tcp_workaround_signed_windows",
1226 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1227 .maxlen = sizeof(u8),
1229 .proc_handler = proc_dou8vec_minmax,
1232 .procname = "tcp_limit_output_bytes",
1233 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1234 .maxlen = sizeof(int),
1236 .proc_handler = proc_dointvec
1239 .procname = "tcp_challenge_ack_limit",
1240 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1241 .maxlen = sizeof(int),
1243 .proc_handler = proc_dointvec
1246 .procname = "tcp_min_tso_segs",
1247 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1248 .maxlen = sizeof(u8),
1250 .proc_handler = proc_dou8vec_minmax,
1251 .extra1 = SYSCTL_ONE,
1254 .procname = "tcp_tso_rtt_log",
1255 .data = &init_net.ipv4.sysctl_tcp_tso_rtt_log,
1256 .maxlen = sizeof(u8),
1258 .proc_handler = proc_dou8vec_minmax,
1261 .procname = "tcp_min_rtt_wlen",
1262 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1263 .maxlen = sizeof(int),
1265 .proc_handler = proc_dointvec_minmax,
1266 .extra1 = SYSCTL_ZERO,
1267 .extra2 = &one_day_secs
1270 .procname = "tcp_autocorking",
1271 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1272 .maxlen = sizeof(u8),
1274 .proc_handler = proc_dou8vec_minmax,
1275 .extra1 = SYSCTL_ZERO,
1276 .extra2 = SYSCTL_ONE,
1279 .procname = "tcp_invalid_ratelimit",
1280 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1281 .maxlen = sizeof(int),
1283 .proc_handler = proc_dointvec_ms_jiffies,
1286 .procname = "tcp_pacing_ss_ratio",
1287 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1288 .maxlen = sizeof(int),
1290 .proc_handler = proc_dointvec_minmax,
1291 .extra1 = SYSCTL_ZERO,
1292 .extra2 = SYSCTL_ONE_THOUSAND,
1295 .procname = "tcp_pacing_ca_ratio",
1296 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1297 .maxlen = sizeof(int),
1299 .proc_handler = proc_dointvec_minmax,
1300 .extra1 = SYSCTL_ZERO,
1301 .extra2 = SYSCTL_ONE_THOUSAND,
1304 .procname = "tcp_wmem",
1305 .data = &init_net.ipv4.sysctl_tcp_wmem,
1306 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1308 .proc_handler = proc_dointvec_minmax,
1309 .extra1 = SYSCTL_ONE,
1312 .procname = "tcp_rmem",
1313 .data = &init_net.ipv4.sysctl_tcp_rmem,
1314 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1316 .proc_handler = proc_dointvec_minmax,
1317 .extra1 = SYSCTL_ONE,
1320 .procname = "tcp_comp_sack_delay_ns",
1321 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1322 .maxlen = sizeof(unsigned long),
1324 .proc_handler = proc_doulongvec_minmax,
1327 .procname = "tcp_comp_sack_slack_ns",
1328 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1329 .maxlen = sizeof(unsigned long),
1331 .proc_handler = proc_doulongvec_minmax,
1334 .procname = "tcp_comp_sack_nr",
1335 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1336 .maxlen = sizeof(u8),
1338 .proc_handler = proc_dou8vec_minmax,
1339 .extra1 = SYSCTL_ZERO,
1342 .procname = "tcp_reflect_tos",
1343 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1344 .maxlen = sizeof(u8),
1346 .proc_handler = proc_dou8vec_minmax,
1347 .extra1 = SYSCTL_ZERO,
1348 .extra2 = SYSCTL_ONE,
1351 .procname = "tcp_ehash_entries",
1352 .data = &init_net.ipv4.sysctl_tcp_child_ehash_entries,
1354 .proc_handler = proc_tcp_ehash_entries,
1357 .procname = "tcp_child_ehash_entries",
1358 .data = &init_net.ipv4.sysctl_tcp_child_ehash_entries,
1359 .maxlen = sizeof(unsigned int),
1361 .proc_handler = proc_douintvec_minmax,
1362 .extra1 = SYSCTL_ZERO,
1363 .extra2 = &tcp_child_ehash_entries_max,
1366 .procname = "udp_rmem_min",
1367 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1368 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1370 .proc_handler = proc_dointvec_minmax,
1371 .extra1 = SYSCTL_ONE
1374 .procname = "udp_wmem_min",
1375 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1376 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1378 .proc_handler = proc_dointvec_minmax,
1379 .extra1 = SYSCTL_ONE
1382 .procname = "fib_notify_on_flag_change",
1383 .data = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1384 .maxlen = sizeof(u8),
1386 .proc_handler = proc_dou8vec_minmax,
1387 .extra1 = SYSCTL_ZERO,
1388 .extra2 = SYSCTL_TWO,
1393 static __net_init int ipv4_sysctl_init_net(struct net *net)
1395 struct ctl_table *table;
1397 table = ipv4_net_table;
1398 if (!net_eq(net, &init_net)) {
1401 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1405 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1406 if (table[i].data) {
1407 /* Update the variables to point into
1408 * the current struct net
1410 table[i].data += (void *)net - (void *)&init_net;
1412 /* Entries without data pointer are global;
1413 * Make them read-only in non-init_net ns
1415 table[i].mode &= ~0222;
1420 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1421 if (!net->ipv4.ipv4_hdr)
1424 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1425 if (!net->ipv4.sysctl_local_reserved_ports)
1431 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1433 if (!net_eq(net, &init_net))
1439 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1441 struct ctl_table *table;
1443 kfree(net->ipv4.sysctl_local_reserved_ports);
1444 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1445 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1449 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1450 .init = ipv4_sysctl_init_net,
1451 .exit = ipv4_sysctl_exit_net,
1454 static __init int sysctl_ipv4_init(void)
1456 struct ctl_table_header *hdr;
1458 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1462 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1463 unregister_net_sysctl_table(hdr);
1470 __initcall(sysctl_ipv4_init);